package com.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.feng.entity.User;
import com.feng.service.IUserService;
import com.feng.util.RedisUtils;

@Controller
//@PropertySource(value = "classpath:config/application.properties")
public class TestController {

	@Resource
	private IUserService userService;
	//@Value("${service.name}")
	private String serviceName;
	@Autowired
	private RedisUtils redisUtils;
	
	//@RequestMapping("toindex")
	public String toindex(HttpServletRequest request){
		
		request.setAttribute("feng", "lvqingfeng");
		return "index";
	}
	@ResponseBody
	@RequestMapping("findUsers")
	public List<User> findUsers(HttpServletRequest request){
		List<User> list=userService.selectAllUsers();
		return list;
	}
	@ResponseBody
	@RequestMapping("findUsersByPage")
	public List<User> findUsersByPage(String pageNum){
		if(pageNum == null ||"".equals(pageNum)){
			pageNum="0";
		}
		List<User> list=userService.selectAllByPage(Integer.parseInt(pageNum));
		return list;
	}
	@ResponseBody
	@RequestMapping("/gemap")
	public Map<String,String> gemap(){
		Map<String,String> map=new HashMap<String,String>();
		map.put("errorcode", "1");
		map.put("content", "springboot成功");
		map.put("serviceName", serviceName);
		return map;
	}
	@ResponseBody
	@RequestMapping("/test")
	public String test(){
		Map<String,String> map=new HashMap<String,String>();
		redisUtils.setString("city", "北京");
		return null;
	}
	
}
